home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12412 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: routine for yesterday's date
  5. Date: 31 Mar 1996 08:43:07 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4jlgir$jsf@news.xs4all.nl>
  8. References: <315c4d0f.19874776@ottnews.shl.com>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. 75323.455@compuserve.com (Bruce Coghill) writes:
  13.  
  14. >Greetings,
  15.  
  16. >In many languages you can specify (reference) a relative date.  To
  17. >find out yesterday's address, In Sybase, for example it is something
  18. >like dayadd(-1).  In dBase you just say "yesterday" in the assignment
  19. >statement.  In my C manual the time.h and time functions are described
  20. >and how I can pull off each element in the structure (like year,
  21. >month, day, day-of-the-year), but it isn't clear to me how to subtract
  22. >a day.  In its 19960329 (format yyymmdd), it is easy.  But what about
  23. >19960401?  I do have a function that converts a date to julian, but
  24. >not the other way.
  25.  
  26. No need to go to julian first.  Use something like:
  27.  
  28. int DIM[12]={31,28,31,30,31,30,31,31,30,31,30,31};
  29.  
  30. if(!--d)
  31. {  
  32.    if(!--m)
  33.    {  m=12;
  34.       y--; }
  35.  
  36.    DIM[1]=(~y&3 && (y%100||!(y%400)))?29:28;
  37.    d=DIM[m-1];
  38. }
  39.  
  40. Frank
  41. --
  42. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  43. ------------------------------------------------------------------------
  44. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  45.